// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

namespace kumo::pollux {
    /// Comparing double against int64:max() like the following would get compile
    /// time error on some compilers(e.g. clang 12 and above):
    ///
    /// ```
    /// double_value <= int64::max()
    /// double_value >= int64::max()
    /// ```
    ///
    /// Here `int64::max()` will be implicitly converted to double, but due to the
    /// floating point nature of double, converting `int64::max()` to double lose
    /// precision(see [1]), so instead of comparing double with int64:max(), we
    /// suggest compare it with the max double value below int64:max() 2 ^ 63 -
    /// 1024 for < or <=, 2 ^ 63 for >, >=.
    ///
    /// [1].https://en.wikipedia.org/wiki/Double-precision_floating-point_format#Precision_limitations_on_integer_values

    /// 2 ^ 63 - 1024
    constexpr double kMaxDoubleBelowInt64Max = 9223372036854774784.0;
    /// 2 ^ 63
    constexpr double kMinDoubleAboveInt64Max = 9223372036854775808.0;

    /// For int128::max()
    ///  2 ^ 127 - 2 ^ 74
    constexpr double kMaxDoubleBelowInt128Max =
            170141183460469212842221372237303250944.0;
} // namespace kumo::pollux
